package base

import (
	"fmt"
	"math"
	"strings"
)

type Calculation struct{}

func CalculationMain(shape string, args ...float64) float64 {
	var area float64
	OptFunc := Calculation{}
	// 面积算法
	if shape == "" {
		shape = "square"
	}
	if args == nil || len(args) == 0 {
		panic("Parameter cannot be empty!")
	}
	for i := 0; i < len(args); i++ {
		if args[i] < 0 {
			panic("Parameter cannot be negative!")
		}
	}
	if strings.ToLower(shape) == "square" {
		area = OptFunc.calculation_square_area(args[0])
	} else if strings.ToLower(shape) == "circular" {
		area = OptFunc.calculation_circular_area(args[0])
	} else if strings.ToLower(shape) == "rectangle" {
		area = OptFunc.calculation_rectangle_area(args[0], args[1])
	}
	fmt.Println(area)
	return area
}

func (c *Calculation) calculation_rectangle_area(length, width float64) float64 {
	return length * width
}

func (c *Calculation) calculation_square_area(side_length float64) float64 {
	return math.Pow(side_length, 2)
}

func (c *Calculation) calculation_circular_area(radius_length float64) float64 {
	return math.Pi * math.Pow(radius_length, 2)
}
